package selenium;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;

public class test7 {
//模拟手机版IOS系统
	public static void main(String[] args1) {
		try {
			//指定设备的分辨率及像素比
			Map<String, Object> deviceMetrics = new HashMap<String, Object>();
			deviceMetrics.put("width", 360);
			deviceMetrics.put("height", 640);
			deviceMetrics.put("pixelRatio", 1);

			Map<String, Object> mobileEmulation = new HashMap<String, Object>();
			mobileEmulation.put("deviceMetrics", deviceMetrics);

			//指定设备的userAgent(此处是一个微信内置浏览器)
			mobileEmulation.put("userAgent", "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_3 like Mac OS X) AppleWebKit/603.3.8 (KHTML, like Gecko) Mobile/14G60 MicroMessenger/6.5.12 NetType/WIFI Language/zh_CN");

			//指定其它启动参数(支持所有Chromium启动参数)
			List<String> args = new ArrayList<String>(); //args
			args.add("window-size=375,685"); //设置浏览器窗口大小
			args.add("disable-infobars");  //取消"Chrome正收到自动测试软件的控制"提示
			args.add("app=https://weshop.chihuoyun.com"); //以app模式打开网页(不显示地址栏, 工具栏等. 需要填上对应的地址)

			Map<String, Object> chromeOptions = new HashMap<String, Object>();
			chromeOptions.put("mobileEmulation", mobileEmulation);
			chromeOptions.put("args", args);
			DesiredCapabilities capabilities = DesiredCapabilities.chrome();
			capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
			WebDriver driver = new ChromeDriver(capabilities);

			driver.get("http://mp.163.com/index.html");
			driver.manage().deleteAllCookies();
			
			
			
			
			
			SimpleDateFormat sdf = new SimpleDateFormat("M/dd/yyyy hh:mm:ss a",Locale.US);
			
			String name = "NTES_SESS";
			String value = "yaQJu0scawjVug26fPhj0z.n.28uBPm4zwm40fuL8_aTFvMZ6bEWi_y2t5h7yFgkVLbGU6oVsHAs8r1TX2AP1wUyqNxcUaW3VjxvM2dddvpPuuCXZ8fVtqf7EskKOdlCOHmhnlaOXrUZcMCupcEHbsDPigPfd0O1d0xLediLzUOoznQcIXvYI8wz_JuxHwYK4";
			String domain = ".mp.163.com";
			String path = "/";
			Date expiry = sdf.parse("5/13/2103 10:31:37 AM");
			Cookie cookie = new Cookie(name, value, domain, path, expiry);
			
			driver.manage().addCookie(cookie);
			driver.get("http://mp.163.com/index.html");
			System.out.println("成功登陆 ");
			Set<Cookie> cookies = driver.manage().getCookies();
			System.out.println("打印cookie");
			/*
			driver.findElement(By.className("j-inputtext dlemail")).sendKeys("aa3338444555@163.com");
			driver.manage().window().maximize();
			driver.findElement(By.id("loginEmail")).sendKeys("aa3338444555@163.com");
			driver.findElement(By.id("loginEmail")).sendKeys("wqw5812@163.com");
			driver.findElement(By.id("loginEmail")).sendKeys("eee3887766@163.com");
			driver.findElement(By.id("loginEmail")).sendKeys("ttt888668@163.com");
			driver.findElement(By.id("loginPassword")).sendKeys("huang147258");
			driver.findElement(By.id("loginBtn")).click();
			driver.findElement(By.linkText("鎴戠殑瑙嗛")).click();
			for (int i = 0; i < 6; i++) {
				driver.findElement(By.linkText("鍙戣棰�)).click();
				driver.findElement(By.id("video-up")).sendKeys("D:\\360鏋侀�娴忚鍣ㄤ笅杞絓\涓�銆婄埗浜层�鍞卞摥鎵�湁鍚紬锛岃瘎濮旈煩绾㈡洿鏄壄澶存摝娉�mp4");
				driver.findElement(By.id("description")).sendKeys("灏忎紮涓�銆婄埗浜层�鍞卞摥浜嗚浼楋紝璇勫闊╃孩鏇存槸鎵ご鎿︽唱锛�);
				driver.findElement(By.id("form-tags-input")).sendKeys("鐖朵翰");
				Actions action = new Actions(driver);
				action.sendKeys(Keys.SPACE).perform();
				driver.findElement(By.id("form-tags-input")).sendKeys("闊╃孩");
				action.sendKeys(Keys.SPACE).perform();
				driver.findElement(By.id("form-tags-input")).sendKeys("璇勫");
				action.sendKeys(Keys.SPACE).perform();
				driver.findElement(By.id("form-tags-input")).sendKeys("鍚紬");
				action.sendKeys(Keys.SPACE).perform();
				driver.findElement(By.id("form-tags-input")).sendKeys("婕斿敱浼�);
				action.sendKeys(Keys.SPACE).perform();
				
				File srcFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
			    try {
			      FileUtils.copyFile(srcFile,new File("d:\\hehe\\screenshot"+i+".png"));
			    } catch (IOException e) {
			      e.printStackTrace();
			    }
				
				driver.findElement(By.xpath("//button[@type='button']")).click();
				driver.findElement(By.linkText("闊充箰")).click();
				driver.findElement(By.xpath("(//button[@type='button'])[2]")).click();
				driver.findElement(By.linkText("婕斿敱浼�)).click();
				driver.findElement(By.xpath("//form[@id='videoPost']/div[2]/div[6]/div/ul/li/a/label")).click();
				WebDriverWait wait = new WebDriverWait(driver, 50);
				wait.until(new ExpectedCondition<WebElement>() {
					@Override
					public WebElement apply(WebDriver d) {
						WebElement ddElement = driver.findElement(By.xpath("//*[@id='auto']/ul/li[1]/input"));
						if (ddElement != null) {
							return ddElement;
						} else {
							return null;
						}
					}
				});
				driver.findElement(By.xpath("(//input[@name='_picUrl'])[5]")).click();
				driver.findElement(By.xpath("//*[@id='videoPost']/div[2]/div[7]/div/button")).click();
				WebElement e = (new WebDriverWait(driver, 50)).until(new ExpectedCondition<WebElement>() {
					@Override
					public WebElement apply(WebDriver arg0) {
						WebElement sDriver = driver
								.findElement(By.xpath("//*[@class='modal fade in']/div[2]/div/div[3]/button"));
						if (sDriver != null) {
							return sDriver;
						} else {
							return null;
						}
					}
				});
				driver.findElement(By.xpath("//*[@class='modal fade in']/div[2]/div/div[3]/button")).click();
			}
			driver.manage().deleteAllCookies();
			driver.get("http://dy.163.com/wemedia/login.html");*/
		} catch (Exception e) {
			e.printStackTrace();
		}
		 /*driver.quit();*/
	}

}
